package cn.lxycx.dataterrace.interceptor.validates;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.lxycx.dataterrace.interceptor.AbsValidateInterceptor;
import cn.lxycx.dataterrace.util.FormVerifys;
import cn.lxycx.dataterrace.util.RegexStr;
import org.apache.log4j.Logger;

import lxycx.util.validate.Validate.Ret;

public class AccountValidate extends AbsValidateInterceptor {
	
	private static Logger log = Logger.getLogger(AccountValidate.class);

	@Override
	public Ret verify(HttpServletRequest req) {
		List<FormVerifys> fl = new ArrayList<FormVerifys>();
		 Map<String,String> param = new LinkedHashMap<String,String>();
		 
		 String url = req.getRequestURI();
		 if(url.indexOf("account/save")>=0){//注册
			 String id = req.getParameter("id");
			 fl.add(new FormVerifys("id",id , true,-101, "无效的ID", RegexStr.ISNUMBER));//
			 if(id!=null){
				 fl.add(new FormVerifys("role", req.getParameter("role"), false,-101, "无效的权限类型","1|2"));//				 
			 }else{
				 fl.add(new FormVerifys("role", req.getParameter("role"), false,-101, "无效的权限类型","0|1|2"));
			 }
			 
			 fl.add(new FormVerifys("account", req.getParameter("account"), false,-101, "无效的账号",null));//
			 fl.add(new FormVerifys("username", req.getParameter("username"), false,-101, "无效的用户名",null));//
			 fl.add(new FormVerifys("department", req.getParameter("department"), false,-101, "无效的部门",null));//
			 fl.add(new FormVerifys("phone", req.getParameter("phone"), false,-101, "无效的手机号码",RegexStr.PHONE));
			 fl.add(new FormVerifys("openid", req.getParameter("openid"), true,-101, "无效的OPENID",null));
		 }
		
		 Ret ret = FormVerifys.Valuedate(fl, param);
		 req.setAttribute("param",param);
		 return ret;
		
	}
	
}
